﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using System.Configuration;
using Language_Editor;
using System.Globalization;
using System.IO;

namespace Text_Finder
{
    //  Summary:
    //      vindue til at ændre i konfigfilen
    public partial class Settings : Telerik.WinControls.UI.RadForm
    {
        Configuration config;
        public Settings()
        {
            InitializeComponent();
            config = ConfigurationManager.OpenExeConfiguration(@"..\..\..\BE\LanguageApp.exe");
            Lbl_Language.Text = config.AppSettings.Settings["Language"].Value;
            Sln_Searcher.Value = config.AppSettings.Settings["SlnFile"].Value;
            Txt_ConStr.Text = config.AppSettings.Settings["ConnectionString"].Value;
            if (config.AppSettings.Settings["VariableName"].Value.Length < 1)
                config.AppSettings.Settings["VariableName"].Value = "Manager";
            Txt_Variable.Text = config.AppSettings.Settings["VariableName"].Value;
        }



        private void Btn_ChangeLanguage_Click(object sender, EventArgs e)
        {
            CultureInfo newInf = new PickLanguage().getNew();
            if (newInf != null)
                Lbl_Language.Text = newInf.Name;
        }

        private void Btn_Save_Click(object sender, EventArgs e)
        {
            config.AppSettings.Settings["Language"].Value = Lbl_Language.Text;
            config.AppSettings.Settings["SlnFile"].Value = Sln_Searcher.Value;
            config.AppSettings.Settings["ConnectionString"].Value = Txt_ConStr.Text;
            if (Txt_Variable.Text.Length > 0)
                config.AppSettings.Settings["VariableName"].Value = Txt_Variable.Text;
            config.Save();
            File.Copy(@"..\..\..\BE\LanguageApp.exe.Config", @"LanguageApp.exe.Config", true);
            Close();
        }

        private void Btn_Cancel_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
